<?php

function getdata($data)
{
    $temp              = [];
    $temp['path']      = $data['path'];
    $temp['component'] = $data['component'];
    $temp['name']      = $data['name'];
    if ($data['hidden'] > -1) {
        $temp['hidden'] = (boolean)$data['hidden'];
    }
    if ($data['always_show'] > -1) {
        $temp['alwaysShow'] = (boolean)$data['always_show'];
    }
    if ($data['redirect']) {
        $temp['redirect'] = $data['redirect'];
    }
    $temp['meta']['title'] = $data['title'];
    $temp['meta']['icon']  = $data['icon'];
    if ($data['no_cache'] > -1) {
        $temp['meta']['noCache'] = (boolean)$data['no_cache'];
    }

    return $temp;
}

function parseTree($permission){
    $routers = [];

    foreach ($permission as $v) {
        $temp = getdata($v);
        foreach ($v['children'] as $vo) {
            $temp['children'][] = getdata($vo);
        }
        $routers[] = $temp;
    }

    return $routers;
}

